<!--This will add a new manager to the database-->
<?php
//written by: Marcos Resendiz
require_once '../php_includes.php';

sqlConnect();
//Checks if the user has entered values in all fields, if not ask them to fill it out completely
if(empty($_POST['managerID']) ||empty($_POST['passWord'])||empty($_POST['fName'])||empty($_POST['lName']))
exit("<p>You must enter values in all fields of the Add Employee form! <br> Click <a href=\"superadmin_setup.php\">here</a> to go back.</p>");
	
else//if the form has been completed then proceed.
{
	//this will hold the manager ID entered.
	$checkMan=$_POST['managerID'];
	//this will check if the manager ID already exists.
	$check = mysql_num_rows(sqlQuery("select EmployeeID FROM Employee WHERE EmployeeID='$checkMan'"));
	//if the ID exists it will display the following
	if($check=='1')
	{
		exit("<font color=red> Manager ID Already Exists. Please click <a href=\"superadmin_setup.php\">here</a> to go back. </font>");	
	}
		else //else if the manager does not exists, it will insert him/her to the DB.
		{
			//is the managers start date
			$startDate=date("m/d/y");
		
			//adds the manager to the database with Employee ID, password, first name, last name, and start date
			$sql2="INSERT INTO Employee (EmployeeID, EmployeePassword, ManagerID, EmployeeFName, EmployeeLName, EmployeeStartDate) VALUES ('$_POST[managerID]','$_POST[passWord]','$_POST[managerID]','$_POST[fName]','$_POST[lName]', '$startDate')";

				if(!sqlQuery($sql2)) //if could not add the manager
					exit("Could not add manager. <br/> Click <a href=\"addmanager.php\">here</a> to go back.");
				else //manager was added successfully
					exit("Manager added.<br/> Click <a href=\"superadmin_setup.php\">here</a> to add another Manager.");
				//Close DB
				sqlExit();
		}
}
	
?> 

